using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using AtletIS.DomainModel.Entities.Web;

namespace AtletIS.Database.Mapping.Web
{
    public class ArticleMap : EntityTypeConfiguration<Article>
    {
        public ArticleMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Title)
                .HasMaxLength(255);

            this.Property(t => t.City)
                .HasMaxLength(100);

            this.Property(t => t.Editor)
                .HasMaxLength(100);

            this.Property(t => t.Perex)
                .HasMaxLength(1000);

            this.Property(t => t.ImagePath)
                .HasMaxLength(255);

            this.Property(t => t.ImageText)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("Articles");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.CategoryId).HasColumnName("CategoryId");
            this.Property(t => t.Title).HasColumnName("Title");
            this.Property(t => t.City).HasColumnName("City");
            this.Property(t => t.Date).HasColumnName("Date");
            this.Property(t => t.Editor).HasColumnName("Editor");
            this.Property(t => t.Perex).HasColumnName("Perex");
            this.Property(t => t.Text).HasColumnName("Text");
            this.Property(t => t.ImagePath).HasColumnName("ImagePath");
            this.Property(t => t.Active).HasColumnName("Active");
            this.Property(t => t.Top).HasColumnName("Top");
            this.Property(t => t.ImageText).HasColumnName("ImageText");

            // Relationships
            this.HasOptional(t => t.ArticlesCategory)
                .WithMany(t => t.Articles)
                .HasForeignKey(d => d.CategoryId);

        }
    }
}
